#version 120
uniform sampler2D u_Sampler;
uniform vec3 u_eyePosition;
uniform vec3 u_lightPoint;

varying vec4 v_Vertex;
varying vec3 v_Normal;
varying vec2 v_TexCoord;

const float ambient = 0.3;
const float gloss = 0.9;

void main() { 
    vec4 texColor = texture2D(u_Sampler, v_TexCoord).bgra;
    vec3 viewDir = normalize(u_eyePosition - v_Vertex.xyz);
    vec3 lightDir = normalize(v_Vertex.xyz - u_lightPoint);
    vec3 reflectDir = reflect(lightDir, v_Normal);
    vec3 halfDir = normalize(-lightDir + viewDir);
    float diffuse = clamp(-dot(v_Normal, lightDir), 0.0, 1.0);
    // float specular = pow(max(0, dot(viewDir, reflectDir)), gloss);
    float specular = pow(max(0, dot(v_Normal, halfDir)), gloss);
    gl_FragColor = (ambient + diffuse + specular) * texColor;
    // gl_FragColor = vec4(viewDir, 1.0);
}
